package com.example.demo.service.Impl;

import com.example.demo.bean.BaseLog;
import com.example.demo.bean.BaseRole;
import com.example.demo.bean.BaseRoleExample;
import com.example.demo.dao.BaseRoleMapper;
import com.example.demo.service.IBaseRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseRoleServiceImpl implements IBaseRoleService {
    @Resource
    private BaseRoleMapper baseRoleMapper;

    @Override
    public List<BaseRole> query(String name) {
        BaseRoleExample example=new BaseRoleExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%" + name + "%");
        }

        List<BaseRole>list=baseRoleMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseRole baseRole) {
        if(baseRole.getId() == null) {
            baseRoleMapper.insert(baseRole);
        }
        else{
            baseRoleMapper.updateByPrimaryKey(baseRole);
        }

    }

    @Override
    public void deleteById(Long id) {
        baseRoleMapper.deleteByPrimaryKey(id);
    }
}